var gblnSaved = false;
$(document).ready(function() {

 });



function startDownload(){

  var pContent  = "";
  var pPoints   = "";
  var pSep      = "**||**";
  var pFileName = document.title + "-" + new Date().toLocaleString();

  //pFileName = prompt("Geben Sie einen Dateinamen an!",pFileName);
  if(pFileName == null) return;
  $('.heatmapAreaChar').each(function(index,obj){
    // DIE '1' AN ZWEITER STELLE BEDEUTET; DASS ES SICH UM KEYCODES HANDELT!
    // DIE ERSTE STELLE BEINHALTET DIE ID DES DOMELEMENTES
    this.updateCharList();
    var pList =  this.HeatPointCharList;

    pPoints = "";
    for(var i = 0; i < pList.length;i++)
      if(pList[i].Count > 0 )
        pPoints = pPoints +pList[i].keyCode + ":" + pList[i].Count +";"; 
    
    if (pPoints.length >0)
      pContent = pContent + $(this).attr('id') +";hmChar;"+ pPoints + "\n";
  });

  $('.heatmapAreaKeyStroke').each(function(index,obj){
    // DIE '1' AN ZWEITER STELLE BEDEUTET; DASS ES SICH UM KEYCODES HANDELT!
    // DIE ERSTE STELLE BEINHALTET DIE ID DES DOMELEMENTES
    var pList =  this.HeatPointKeyStrokeList;

    pPoints = "";
    for(var i = 0; i < pList.length;i++)
      if(pList[i].Count > 0 )
        pPoints = pPoints +pList[i].keyCode + ":" + pList[i].Count +";"; 
    
    if (pPoints.length >0)
      pContent = pContent + $(this).attr('id') +";hmKeyStroke;"+ pPoints + "\n";
  });
  
  console.log(pContent);
  var blob = new Blob([pContent], {type: "text/plain;charset=utf-8"});


  saveAs(blob, pFileName+".txt");
  gblnSaved = true;

  var pLogFile = pContent.split("\n");
  for(var i = 0; i < pLogFile.length;i++){
    loadDataIntoElement(pLogFile[i]);
  }
}

//.heatmapAreaChar, .heatmapAreaKeyStroke


